package com.code.task.worker;

import com.code.task.service.ItemIndexService;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author lyf
 * @date 2021-06-15 下午4:11
 */
@Slf4j
public class ItemIndexWorker implements Callable<Boolean> {

    // 待索引门店id列表
    private List<Long> indexStoreIds;

    // 业务Bean，通过构造函数手动注入
    private ItemIndexService itemIndexService;

    public ItemIndexWorker(List<Long> indexStoreIds, ItemIndexService itemIndexService) {
        this.indexStoreIds = indexStoreIds;
        this.itemIndexService = itemIndexService;
    }

    @Override
    public Boolean call() throws Exception {

        for (Long storeId : indexStoreIds) {
            try {
                itemIndexService.doSomething(storeId);
            } catch (Exception e) {
                log.error("error. ", e);
            }
        }
        return true;
    }
}
